<?php
$this->getTypes();

// 帐号限制
if($_REQUEST['username']){
    $_REQUEST['username']=wjStrFilter($_REQUEST['username']);
    if(!ctype_alnum($_REQUEST['username'])) throw new Exception('用户名包含非法字符,请重新输入');
    $userWhere="and b.username like '%{$_REQUEST['username']}%'";
}

//期号
if($_REQUEST['actionNo']){
    $_REQUEST['actionNo']=wjStrFilter($_REQUEST['actionNo']);
    $actionNoWhere=" and b.actionNo='{$_REQUEST['actionNo']}'";
}

// 彩种限制
if($_REQUEST['type']=intval($_REQUEST['type'])){
    $typeWhere=" and b.type={$_REQUEST['type']}";
}
// 下注来源限制
//if($_REQUEST['betType']!=''){
//$_REQUEST['betType']=wjStrFilter($_REQUEST['betType']);
//$betTypeWhere=" and b.betType={$_REQUEST['betType']}";
//}

// 时间限制
if($_REQUEST['fromTime'] && $_REQUEST['toTime']){
    $fromTime=strtotime($_REQUEST['fromTime']);
    $toTime=strtotime($_REQUEST['toTime'])+24*3600;
    $timeWhere="and b.actionTime between $fromTime and $toTime";
}elseif($_REQUEST['fromTime']){
    $fromTime=strtotime($_REQUEST['fromTime']);
    $timeWhere="and b.actionTime>=$fromTime";
}elseif($_REQUEST['toTime']){
    $toTime=strtotime($_REQUEST['toTime'])+24*3600;
    $timeWhere="and b.actionTime<$fromTime";
}else{
    $timeWhere=' and b.actionTime>'.strtotime('00:00');;
}
$sql="select * from {$this->prename}bets b where 1 $timeWhere $actionNoWhere $typeWhere $betTypeWhere $userWhere order by b.id desc";
if($_REQUEST['id']){
    $_REQUEST['id']=wjStrFilter($_REQUEST['id']);
    if(!ctype_alnum($_REQUEST['id'])) throw new Exception('单号包含非法字符,请重新输入');
    $sql="select * from {$this->prename}bets b where b.wjorderId='{$_REQUEST['id']}'";}

$data=$this->getPage($sql, $this->page, $this->pageSize);

$mname=array(
    '2.00'=>'元',
    '0.20'=>'角',
    '0.02'=>'分'
);
//echo $sql;
?>
<article class="module width_full">
    <input type="hidden" value="<?=$this->user['username']?>" />
    <button style="margin-bottom: 20px;margin-left: 5px;margin-top: 8px;width: 100px;height: 30px;text-align: center;cursor: pointer;" id="kajiang">全部卡奖</button>
    <header>
        <h3 class="tabs_involved">普通投注
            <div class="submit_link wz">
                <form action="/admin778899.php/business/betLog" target="ajax" call="defaultSearch" dataType="html">
                    期号<input type="text" class="alt_btn" name="actionNo" style="width:90px;" value="<?=$_REQUEST['actionNo']?>"/>
                    单号<input type="text" class="alt_btn" name="id" style="width:90px;"/>&nbsp;&nbsp;
                    会员<input type="text" class="alt_btn" name="username" style="width:90px;"/>&nbsp;&nbsp;
                    时间从 <input type="date" class="alt_btn" name="fromTime"/> 到 <input type="date" name="toTime" class="alt_btn"/>&nbsp;&nbsp;
                    <select style="width:100px;" name="type">
                        <option value="">全部彩种</option>
                        <?php if($this->types) foreach($this->types as $var){
                            if($var['enable'] && !$var['isDelete']){
                                ?>
                                <option value="<?=$var['id']?>" title="<?=$var['title']?>"><?=$this->ifs($var['shortName'], $var['title'])?></option>
                            <?php }} ?>
                    </select>&nbsp;&nbsp;
                    <input type="submit" value="查找" class="alt_btn">
                    <input type="reset" value="重置条件">
                    <a  href="" button="修改:dataAddCode|取消:defaultCloseModal"   target="modal" modal="true" width="800" onclick="batch_update(this)">批量修改</a>
                </form>
            </div>
        </h3>
    </header>

    <table class="tablesorter" cellspacing="0">
        <thead>
        <tr>
            <th><input type="checkbox" id="ck" onclick="check_all(this)">选中</th>
            <th>单号</th>
            <th>用户名</th>
            <th>投注时间</th>
            <th>彩种</th>
            <th>玩法组</th>
            <th>期号</th>
            <th>投注号码</th>
            <th>投注金额</th>
            <th>中奖金额</th>
            <th>退水金额</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="nav01">
        <?php if($data['data']) foreach($data['data'] as $var){ ?>
            <tr data-code='<?=json_encode($var)?>'>
                <td><input type="checkbox" name="ids[]" value="<?=$var['id']?>"></input></td>
                <td><a href="/admin778899.php/business/betInfo/<?=$var['id']?>" button="确定:defaultCloseModal" title="投注信息" width="510" target="modal"><?=$var['wjorderId']?></a></td>
                <td><?=$var['username']?></td>
                <td><?=date('m-d H:i', $var['actionTime'])?></td>
                <td><?=$this->ifs($this->types[$var['type']]['shortName'],$this->types[$var['type']]['title'])?></td>
                <td><?=$var['Groupname']?></td>
                <td><?=$var['actionNo']?></td>
                <td data-code="<?=$var['actionData']?>"><?=$this->CsubStr($var['actionData'],0,10)?></td>
                <td><?=number_format($var['money'], 2)?></td>
                <td>
                    <?php
                    if($var['isDelete']==1){
                        echo '已撤单';
                    }else{
                        if($var['lotteryNo']){
                            if($var['bonus']>0){
                                echo '<span style="color:red;">'.number_format($var['bonus'], 2).'</span>';
                            }else{
                                echo '<span>'.number_format($var['bonus'], 2).'</span>';
                            }
                        }else{
                            echo '未开奖';
                        }
                    }
                    ?>
                </td>
                <td><?=$var['rebateMoney']?></td>
                <td>
                    <?php if($var['lotteryNo'] || $var['isDelete']==1){ ?>--<?php }else{ ?>
                    <a href="/admin778899.php/business/betInfoUpdate/<?=$var['id']?>" button="修改:dataAddCode|取消:defaultCloseModal" title="修改投注信息" width="510" target="modal" modal="true">修改</a>
                    <?php //if($var['kajiang'] == 0){?>
                    <!--                    <span class="kajiang" style="cursor: pointer;color: #77BACE;" ajaxhref="/admin778899.php/business/kajiang/--><?//=$var['id']?><!--"  title="卡奖" width="510" >卡奖</span>-->
                    <?php //} else {?>
                    <!--                     <span class="delkajiang" style="cursor: pointer;color: #77BACE;" ajaxhref="/admin778899.php/business/delkajiang/--><?//=$var['id']?><!--"  title="取消卡奖" width="510" >取消卡奖</span>-->
                    <?php //}?>
                </td><?php } ?>
            </tr>
        <?php }else{ ?>
            <tr>
                <td colspan="13" align="center">暂时没有投注记录。</td>
            </tr>
        <?php } ?>
        </tbody>
        <script>
            function check_all(obj)
            {
                var is_checked = obj.checked;

                var nodes = document.getElementsByName('ids[]');
                for (var i=0; i<nodes.length; i++)
                    nodes[i].checked = is_checked;
            }

            function batch_update(obj)
            {
                var ids = new Array();
                var nodes = document.getElementsByName('ids[]');
                for (var i=0; i<nodes.length; i++)
                {
                    if (nodes[i].checked)
                        ids.push(nodes[i].value);
                }

                var ids_str = ids.join(',');
                obj.href = "/admin778899.php/business/betInfoUpdateBatch/" + ids_str;
                // $('<div class="modal"><iframe frameborder="0" src="/admin778899.php/business/betInfoUpdateBatch/' + ids_str + '" style="width:800px;height:300px;"></iframe></div>')
                // .dialog({
                // 	title:'批量修改投注信息',
                // 	width:800,
                // 	// buttons:{
                // 	// 	"确定":function(event,ui){
                // 	// 		frames[frames.length-1].document.forms[0].submit();
                // 	// 	},
                // 	// 	"取消":function(event,ui){
                // 	// 		$(this).dialog("destroy");
                // 	// 	}
                // 	// }
                // });
            }
        </script>
    </table>
    <footer>
        <?php
        $rel=get_class($this).'/betLog-{page}?'.http_build_query($_GET,'','&');
        $this->display('inc/page.php', 0, $data['total'], $rel, 'betLogSearchPageAction');
        ?>
    </footer>
</article>
<script type="text/javascript">
    ghhs("nav01","tr");
</script>
<script>
    $('#kajiang').click(function () {
        $.ajax({
            url: '/admin778899.php/business/kajiang2/',
            success: function () {
                alert('卡奖成功');
            }
        })
    });

    // $(function(){
    //     a();
    //     b();
    //     function a() {
    //         $('.kajiang').click(function () {
    //             var _this = $(this);
    //             $.ajax({
    //                 url: _this.attr('ajaxhref'),
    //                 success: function () {
    //
    //                     var ids = _this.attr('ajaxhref').split('/')[_this.attr('ajaxhref').split('/').length - 1];
    //
    //                     _this.parent().append('<span class="delkajiang" style="cursor: pointer;color: #77BACE;" ajaxhref="/admin778899.php/business/delkajiang/' + ids + '"  title="取消卡奖" width="510" >取消卡奖</span>');
    //                     _this.remove();
    //                     a();
    //                     b();
    //                 }
    //             })
    //         });
    //     }
    //     function b () {
    //         $('.delkajiang').click(function () {
    //             var _this = $(this);
    //             $.ajax({
    //                 url: _this.attr('ajaxhref'),
    //                 success: function () {
    //
    //                     var ids = _this.attr('ajaxhref').split('/')[_this.attr('ajaxhref').split('/').length - 1];
    //
    //                     _this.parent().append('<span class="kajiang" style="cursor: pointer;color: #77BACE;" ajaxhref="/admin778899.php/business/kajiang/' + ids + '"  title="卡奖" width="510" >卡奖</span>');
    //                     _this.remove();
    //                     a();
    //                     b();
    //                 }
    //             })
    //         });
    //     }
    // })
</script>